<template>
    <van-nav-bar title="详情页" left-text="返回" left-arrow @click-left="() => { $router.back() }" fixed />
    <div style="height: 50px;"></div>
    <div v-html="detailDate.goods_introduce"></div>
    <van-action-bar>
        <van-action-bar-icon icon="chat-o" text="客服" color="#ee0a24" />
        <van-action-bar-icon icon="cart-o" text="购物车" />
        <van-action-bar-icon icon="star" text="已收藏" color="#ff5000" />
        <van-action-bar-button type="warning" @click="gocart" text="加入购物车" />
        <van-action-bar-button type="danger" text="立即购买" />
    </van-action-bar>
</template>

<script setup>
import { ref } from 'vue'
import { useRoute } from 'vue-router'
let route = new useRoute()
console.log(route.params.goods_id)
import { detailApi } from '@/api/api'
let detailDate = ref([])
detailApi(route.params.goods_id).then(res => {
    console.log('详情数据', res)
    detailDate.value = res.data.message
})
import { useCounterStore } from '@/stores/cart'
const store = useCounterStore()
import { useRouter } from 'vue-router'
let router = new useRouter()
import { showToast } from 'vant';
const gocart = ()=>{
    // 判断是否登录
    let token = localStorage.getItem('token');
    if(!token){
        // 未登录
        showToast({
            type: 'fail',
            message: '请先登录',
            onClose() {
                // 关闭后进行跳转
                router.push('/login')
            }
        })
    }else{
        // 利用pinia中的公共方法 将数据 加入购物策车
       
        // 跳转到购物车
        store.addCart(detailDate.value,route.params.goods_id)
        router.push('/home/cart')
    }
}
</script>

<style lang="scss" scoped></style>